package moe.kotake.webbehw.controller;


import moe.kotake.webbehw.entity.user;
import moe.kotake.webbehw.service.userService;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@WebMvcTest(basicSMSinRestApi.class)
public class SMStest_WebMVC {

    @Autowired
    private MockMvc mockMvc;

    @MockBean
    private userService User;

    @BeforeEach
    void setUp() {
        given(this.User.getUserById(0L))
                .willReturn(new user(0L,"test","test","test"));
    }

    @AfterEach
    void tearDown(){}

    @Test
    void geetUser() throws Exception {
        this.mockMvc
                .perform(get("/user/129")
                    .accept(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.name").value("test"))
                .andExpect(jsonPath("$.email").value("test"))
                .andExpect(jsonPath("$.password").value("test"))
        ;
    }
}
